﻿package mortal.game.view.autoArena.renderer
{
    import Message.DB.Tables.*;
    import com.mui.controls.*;
    import fl.data.*;
    import flash.display.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.autoArena.view.*;
    import mortal.game.view.common.*;

    public class AutoArenaRankRuleRenderer extends GCellRenderer
    {
        private var _rankIcon:GImageBitmap;
        private var _rankTxt:GImageBitmap;
        private var _itemList:GTileList;
        private var _ruleData:TAutoArenaReward;

        public function AutoArenaRankRuleRenderer()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.AutoArena_CategoryBar_upSkin, 0, 0, this));
            this._rankIcon = UIFactory.gImageBitmap("", 10, 14, this);
            this._rankTxt = UIFactory.gImageBitmap(ImagesConst.AutoArena_Rank_From1, 74, 22 + 2, this);
            this.pushUIToDisposeVec(UIFactory.bg(205 + 12 + 56, 6 + 2, 148 + 4, 51, this));
            this._itemList = UIFactory.tileList(214 + 12 + 56, 10 + 3, 144, 42, this);
            this._itemList.columnWidth = 47;
            this._itemList.rowHeight = 41;
            this._itemList.horizontalGap = 0;
            this._itemList.verticalGap = 0;
            this._itemList.setStyle("skin", new Bitmap());
            this._itemList.setStyle("cellRenderer", AutoArenaItemListCellRenderer);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._ruleData = param1 as TAutoArenaReward;
            if (this._ruleData)
            {
                if (this._ruleData.minRank == 1)
                {
                    this._rankIcon.imgUrl = ImagesConst.AutoArena_RankIcon_Big;
                }
                if (this._ruleData.minRank == 2)
                {
                    this._rankIcon.imgUrl = ImagesConst.AutoArena_RankIcon_Mid;
                }
                if (this._ruleData.minRank == 6)
                {
                    this._rankIcon.imgUrl = ImagesConst.AutoArena_RankIcon_Small;
                }
                this._rankTxt.imgUrl = "AutoArena_Rank_From" + this._ruleData.minRank;
                this.updateItemList();
            }
            return;
        }// end function

        private function updateItemList() : void
        {
            var _loc_3:ItemData = null;
            var _loc_1:Array = [];
            if (this._ruleData.exp > 0)
            {
                _loc_3 = new ItemData(180011015);
                _loc_1.push(_loc_3);
            }
            if (this._ruleData.unit1 > 0)
            {
                _loc_3 = new ItemData(this._ruleData.unit1);
                _loc_3.itemAmount = this._ruleData.num1 / 100;
                _loc_1.push(_loc_3);
            }
            if (this._ruleData.itemCode > 0)
            {
                _loc_3 = new ItemData(this._ruleData.itemCode);
                _loc_1.push(_loc_3);
            }
            var _loc_2:* = new DataProvider();
            _loc_2.addItems(_loc_1);
            this._itemList.dataProvider = _loc_2;
            this._itemList.drawNow();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._rankIcon.dispose();
            this._rankIcon = null;
            this._rankTxt.dispose();
            this._rankTxt = null;
            this._itemList.dispose();
            this._itemList = null;
            this._ruleData = null;
            return;
        }// end function

    }
}
